package com.yan.pojo4;

import com.yan.pojo3.Rent;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

//生成代理类
public class ProxyInvocationhandler implements InvocationHandler {

    //被代理的接口
    private Object targer;

    public void setTarger(Object targer) {
        this.targer = targer;
    }

    //生成代理的类
    public Object getProxy() {
       return Proxy.newProxyInstance(this.getClass().getClassLoader(),
               targer.getClass().getInterfaces(), this);
    }


    //处理代理的类 并返回结果
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
       //动态代理的本质 就是反射机制的实现
        Object invoke = method.invoke(targer, args);

        return invoke;
    }
}
